#include "FirmwareUpdater.h"

#include <filesystem>

#include "ProcessCreator.h"
#include "common.h"



FirmwareUpdater::FirmwareUpdater() {
    //ctor
}

FirmwareUpdater::~FirmwareUpdater() {
    //dtor
}


bool FirmwareUpdater::unpack() {
    std::filesystem::create_directory(UPDATE_TEMP_DIR);
    const char * args[] = {nullptr, "-xzf", DOWNLOAD_PATHNAME.data(), "-C", UPDATE_TEMP_DIR.data(), nullptr};
    return 0 == ProcessCreatorSingleton::instance().runProcess("/bin/tar", "tar", args);
}


bool FirmwareUpdater::runUpdateScript() {
    const char * args[] = {nullptr, nullptr, UPDATE_TEMP_DIR.data(), nullptr};
    return 0 == ProcessCreatorSingleton::instance().runScript(FIRMWARE_UPDATE_SCRIPT, args);
}


void FirmwareUpdater::clearTemp(){
    std::filesystem::remove_all(UPDATE_TEMP_DIR);
}



